package top.bulk.timeWheel;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.time.LocalTime;

/**
 * 多级时间论测试
 *
 * @author 散装java
 * @date 2024-12-14
 */
@Slf4j
public class MultiTimeWheelTest {
    public static void main(String[] args) throws InterruptedException, IOException {
        MultiTimeWheel timeWheel = new MultiTimeWheel();
        timeWheel.start();

        int[] arr = new int[]{3, 24, 67, 115, 162, 163};

        // 添加任务
        new Thread(() -> {
            for (int i : arr) {
                TimeTask task = new TimeTask(() -> log.info(LocalTime.now() + ": first exec task [" + i + "]"), i);
                timeWheel.addTask(task);
            }
        }).start();
        
        Thread.sleep(15 * 1000);

        new Thread(() -> {
            for (int i : arr) {
                TimeTask task = new TimeTask(() -> log.info(LocalTime.now() + ": second exec task [" + i + "]"), i);
                timeWheel.addTask(task);
            }
        }).start();
        // 阻塞
        System.in.read();
    }
}
